import router from '@/router'
import api from './api'
import { useUserStore } from '@/stores/user'
// 无感刷新
export async function refreshToken() {
  const store = useUserStore()
  if (!store.accessToken && store.refreshToken) {
    await api.get('/refreshToken?refreshToken=' + store.refreshToken)
  }
}
// 注册
export async function register(fromData) {
  const res = await api.post('/register', fromData)
  return res.data
}
// 登录
export async function login(fromData) {
  const res = await api.post('/login', fromData)
  if (res.data.code === 10000) {
    router.push({ name: "main" })
  }
}
// 获取用户列表
export async function getUserList(data) {
  const res = await api.get('/users', { params: data })
  return res.data.data
}
// 删除用户
export async function deleteUser(data) {
  const res = await api.delete('/user', { params: data })
  return res.data
}
// 编辑用户
export async function editUser(data) {
  const res = await api.post('/user/edit', data)
  return res.data
}
// 获取房屋表格
export async function getHouse(data) {
  const res = await api('/room/list', { params: data })
  return res.data.data
}
// 删除房屋
export async function deleteHouse(data) {
  const res = await api.delete('/room/list', { params: data })
  return res.data
}
// 新增房屋
export async function addHouse(data) {
  const res = await api.put('/room/list', data)
  return res.data
}
// 编辑房屋
export async function editHouse(data) {
  const res = await api.post('/room/list', data)
  return res.data
}
